package com.aixin.csopservice.repository;

import com.aixin.csopservice.domain.MessageDomain;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MessageRepository extends JpaRepository<MessageDomain,Long> {


    @Query(value = "SELECT * FROM message  WHERE 1=1 " +
            "and (:custName is  null or custName = :custName)" +
            "and (:custPhoneNum is  null or custPhoneNum = :custPhoneNum)" +
            "and (:templatesID is  null or templatesID = :templatesID)" +
            "and (:messageStatus is  null or messageStatus = :messageStatus)" +
            "and (:startTime is  null or createTime < :startTime)" +
            "and (:endTime is  null or createTime < :endTime)",nativeQuery = true)
    Page<MessageDomain> getMessage(@Param("custName") String custName,
                                   @Param("custPhoneNum") String custPhoneNum,
                                   @Param("templatesID") String templatesID,
                                   @Param("messageStatus") int messageStatus,
                                   @Param("startTime") String startTime,
                                   @Param("endTime") String endTime, Pageable pageRequest);
}
